package com.ruoyi.web.controller.system;

import java.util.List;
import java.util.Map;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TourismAppointment;
import com.ruoyi.system.service.ITourismAppointmentService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 预约信息配置表Controller
 *
 * @author gqd
 * @date 2020-12-23
 */
@RestController
@RequestMapping("/system/appointment")
public class TourismAppointmentController extends BaseController
{
    @Autowired
    private ITourismAppointmentService tourismAppointmentService;

    /**
     * 查询预约信息配置表列表
     */
    @PreAuthorize("@ss.hasPermi('system:appointment:list')")
    @GetMapping("/list")
    public TableDataInfo list(TourismAppointment tourismAppointment)
    {
        startPage();
        List<TourismAppointment> list = tourismAppointmentService.selectTourismAppointmentList(tourismAppointment);
        return getDataTable(list);
    }

    /**
     * 导出预约信息配置表列表
     */
    @PreAuthorize("@ss.hasPermi('system:appointment:export')")
    @Log(title = "预约信息配置表", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TourismAppointment tourismAppointment)
    {
        List<TourismAppointment> list = tourismAppointmentService.selectTourismAppointmentList(tourismAppointment);
        ExcelUtil<TourismAppointment> util = new ExcelUtil<TourismAppointment>(TourismAppointment.class);
        return util.exportExcel(list, "appointment");
    }

    /**
     * 获取预约信息配置表详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:appointment:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(tourismAppointmentService.selectTourismAppointmentById(id));
    }

    /**
     * 新增预约信息配置表
     */
    @PreAuthorize("@ss.hasPermi('system:appointment:add')")
    @Log(title = "预约信息配置表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TourismAppointment tourismAppointment)
    {
        return toAjax(tourismAppointmentService.insertTourismAppointment(tourismAppointment));
    }

    /**
     * 修改预约信息配置表
     */
    @PreAuthorize("@ss.hasPermi('system:appointment:edit')")
    @Log(title = "预约信息配置表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TourismAppointment tourismAppointment)
    {
        return toAjax(tourismAppointmentService.updateTourismAppointment(tourismAppointment));
    }

    /**
     * 删除预约信息配置表
     */
    @PreAuthorize("@ss.hasPermi('system:appointment:remove')")
    @Log(title = "预约信息配置表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tourismAppointmentService.deleteTourismAppointmentByIds(ids));
    }

    @PostMapping("/selectAppointment")
    public AjaxResult selectAppointment(@RequestBody Map map){
        String stateTimes = (String) map.get("stateTimes");
        return tourismAppointmentService.selectAppointment(stateTimes);
    }

}
